<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>
</head>

<body>
<?php
include("../connection/connection.php");
include("reportFunctions.php");
$distId=$_REQUEST['distId'];
//$sqlReport = "select distinct block_name as BName from tbl_lookup_location loc,tbl_dtls_q1_main main where main.district_id=".$distId." and loc.block_id = main.block_id order by block_name";
$sqlReport = "select distinct type_scheme from tbl_dtls_q1_main where district_id=".$distId;
//echo $sqlReport;
$queryReport = mysql_query($sqlReport);

?>
<table border="0" width="878" cellspacing="0" cellpadding="0">
	<tr>
		<td width="878" height="26" bgcolor="#E9E9E9">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
	  <font face="Verdana" color="#224568">Scheme wise block wise service level (as per PHED)</font></span></td>
	</tr>
	<tr>
	  <td bgcolor="#E9E9E9" height="26"><div align="center"><font face="Verdana" style="font-size: 9pt; font-weight: 700" color="#224568">Table 7 </font></div></td>
  </tr>
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="870" cellspacing="0" cellpadding="0" height="47" bgcolor="#C5D8EB">
			<tr>
				
				<td width="46" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Type of Scheme</font></td>
				<td align="center" width="818" valign="top"><table border="1" width="825" cellspacing="0" cellpadding="0" height="49" style="border: 1px solid #BBD1E8" bgcolor="#C5D8EB">
				  <tr>
				<td width="170" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt">
			  Name of Block </font></td>
				<td width="162" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Present Population </font></td>
				<td width="191" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Quantity of water supplied (KLD)</font></td>
				<td width="292" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Service Level (lpcd)</font></td>
			</tr></table></td></tr>
		<?php
			while($rowReport = mysql_fetch_array($queryReport)) {
			if($rowReport['type_scheme']!='RWSS')
			{
		
		$Totpop=0;
		$Totwat=0;
		$Totservicelevel=0;
		?>
		    
			<tr>
				
				<td align="center" width="46" valign="top"><font style="font-size: 8.5pt" face="Verdana"><?php echo $rowReport['type_scheme']; ?></font>
				</td>
				
				<td align="center" width="818" valign="top"><table border="1" width="833" cellspacing="0" cellpadding="0" height="49" bordercolor="#C5D8EB" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
				<?php 
				$sqlReportScheme="SELECT main.type_scheme, sum(main.`present_population`) population,main.`block_id`,sum(last.water_supply) water FROM `tbl_dtls_q1_main` main,tbl_dtls_q1_last last where main.`district_id` = ".$distId." and main.`type_scheme`='".$rowReport['type_scheme']."' and last.loc_id=main.id group by `block_id`"; 
				
				$queryReportScheme = mysql_query($sqlReportScheme);
				while($rowReportScheme = mysql_fetch_array($queryReportScheme)) {
				if($rowReportScheme['population']==0)
				{
				$serviceLevel="0.00";
				}else{
				$serviceLevel=number_format(($rowReportScheme['water']*1000)/$rowReportScheme['population'],2,'.','');}
				?>
				<tr>
				<td align="center" width="170"><font style="font-size: 8.5pt" face="Verdana"><?php echo getName('block',$rowReportScheme['block_id']);//$rowReportScheme['block_name']; ?></font></td>
				<td align="center" width="164"><font style="font-size: 8.5pt" face="Verdana"><?php echo $pop=$rowReportScheme['population']; ?></font></td>
				<td align="center" width="191"><font style="font-size: 8.5pt" face="Verdana"><?php echo $wat=number_format($rowReportScheme['water'],2,'.',''); ?></font></td>
				<td align="center" width="298"><font style="font-size: 8.5pt" face="Verdana"><?php echo $ser=$serviceLevel; ?></font></td>
			</tr>
			
			<?php 
			$Totpop+=$pop;
			$Totwat+=$wat;
			$Totservicelevel+=$ser;
			} ?>
			<tr>
				<td align="center" width="170" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana">Total</font></td>
				<td align="center" width="164" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Totpop; //$rowReportScheme['population']; ?></font></td>
				<td align="center" width="191" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($Totwat,2,'.','');//$rowReportScheme['water']; ?></font></td>
				<td align="center" width="298" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $Totservicelevel;//$serviceLevel; 
				if($Totpop==0)
				{
				echo "0.00";
				}else{
				echo number_format(($Totwat*1000/$Totpop),2,'.','');}
				?></font></td>
			</tr>
			</table></td></tr>
			
			
			<?php 
			//$slNo++;
			$GrandTotal1+=$Totpop;
			$GrandTotal2+=$Totwat;
			$GrandTotal3+=$Totservicelevel;
			} }?>
			
			<tr>
				<td width="46" align="left"></td>
				
				<td align="left" width="818">
				<table width="832">
				<tr>
				<td align="center" width="165" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana">Grand Total</font></td>
				<td align="center" width="165" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal1;?></font></td>
				<td align="center" width="188" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($GrandTotal2,2,'.','');?></font></td>
				<td align="center" width="294" bgcolor="#E9E9E9"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $GrandTotal3;
				if($GrandTotal1==0)
				{
				echo "0.00";
				}else{
				echo number_format(($GrandTotal2*1000/$GrandTotal1),2,'.','');}
				?></font></td>
				</tr>
				</table>
				</td>
				
				
			</tr>
		</table>		</td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


</body>

</html>